
package org.come.until;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicScrollBarUI;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class ScrollUI2 extends BasicScrollBarUI {
    private final Color frameColor = new Color(23, 11, 15);
    private JButton up;
    private JButton down;
    private ImageIcon[] upBtnIcons;
    private ImageIcon[] downBtnIcons;
    public ScrollUI2() {
    }

    @Override
    public Dimension getPreferredSize(JComponent c) {
        return new Dimension(17, 17);
    }

    @Override
    public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
        super.paintThumb(g, c, thumbBounds);
        int tw = thumbBounds.width;
        int th = thumbBounds.height;
        g.translate(thumbBounds.x, thumbBounds.y);
        Graphics2D g2 = (Graphics2D)g;
        GradientPaint gp = null;
        if (this.scrollbar.getOrientation() == 1) {
            gp = new GradientPaint(0.0F, 0.0F, new Color(245, 243, 187), (float)tw, 0.0F, new Color(179, 174, 110));
        }

        g2.setPaint(gp);
        g2.fillRoundRect(0, 0, tw, th, 0, 0);//上角
        g2.setColor (new Color(142, 140, 140, 0));// 透明
        g2.drawRoundRect(0, 0, tw, th, 0, 0);//下角
    }

    @Override
    public void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
        Graphics2D g2 = (Graphics2D)g;
        GradientPaint gp = null;
        if (this.scrollbar.getOrientation() == 1) {
            gp = new GradientPaint(0.0F, 0.0F, new Color(245, 245, 187, 0), (float)trackBounds.width, 0.0F, new Color(161, 161, 154));
        }

        if (this.scrollbar.getOrientation() == 0) {
            gp = new GradientPaint(0.0F, 0.0F, new Color(232, 10, 9), 0.0F, (float)trackBounds.height, new Color(223, 4, 8));
        }

        g2.setPaint(gp);
        g2.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
        g2.setColor(new Color(155, 128, 15));
        g2.drawRect(trackBounds.x, trackBounds.y, trackBounds.width - 1, trackBounds.height - 1);
        if (this.trackHighlight == 1) {
            this.paintDecreaseHighlight(g);
        }

        if (this.trackHighlight == 2) {
            this.paintIncreaseHighlight(g);
        }

    }

    @Override
    protected JButton createDecreaseButton(int orientation) {
        try {
            this.upBtnIcons = CutButtonImage.cuts("img/shoptao/sctop.png");
        } catch (Exception var3) {
            var3.printStackTrace();
        }


        this.up = new JButton();
        this.up.setBorderPainted(false);
        this.up.setContentAreaFilled(false);
        this.up.setBorder((Border)null);
        this.up.setBounds(0, 0, 21, 21);
        this.up.setIcon(this.upBtnIcons[0]);
        this.up.addMouseListener(new MouseListener() {
            @Override
            public void mouseReleased(MouseEvent e) {
                ScrollUI2.this.up.setIcon(ScrollUI2.this.upBtnIcons[1]);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                ScrollUI2.this.up.setIcon(ScrollUI2.this.upBtnIcons[2]);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                ScrollUI2.this.up.setIcon(ScrollUI2.this.upBtnIcons[0]);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                ScrollUI2.this.up.setIcon(ScrollUI2.this.upBtnIcons[1]);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
            }
        });
        return this.up;
    }



    @Override
    protected JButton createIncreaseButton(int orientation) {
        try {
            this.downBtnIcons = CutButtonImage.cuts("img/shoptao/scdown.png");
        } catch (Exception var3) {
            var3.printStackTrace();
        }

        this.down = new JButton();
        this.down.setBorderPainted(false);
        this.down.setContentAreaFilled(false);
        this.down.setFocusable(false);
        this.down.setBorder((Border)null);
        this.down.setBounds(0, 0, 21, 21);
        this.down.setIcon(this.downBtnIcons[0]);
        this.down.addMouseListener(new MouseListener() {
            @Override
            public void mouseReleased(MouseEvent e) {
                ScrollUI2.this.down.setIcon(ScrollUI2.this.downBtnIcons[1]);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                ScrollUI2.this.down.setIcon(ScrollUI2.this.downBtnIcons[2]);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                ScrollUI2.this.down.setIcon(ScrollUI2.this.downBtnIcons[0]);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                ScrollUI2.this.down.setIcon(ScrollUI2.this.downBtnIcons[1]);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
            }
        });
        return this.down;
    }
}
